package gui;

/**
 * Classe que mostra os amigos a serem adicionados.
 */
import java.util.Iterator;

import sistema.Sistema;

import com.trolltech.qt.core.Qt;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QDialog;
import com.trolltech.qt.gui.QIcon;
import com.trolltech.qt.gui.QMessageBox;
import com.trolltech.qt.gui.QPushButton;
import com.trolltech.qt.gui.QScrollArea;
import com.trolltech.qt.gui.QScrollBar;
import com.trolltech.qt.gui.QVBoxLayout;
import com.trolltech.qt.gui.QWidget;

import excecoes.ContaException;

public class AcceptFriendsDialog extends QDialog{
	
	private QScrollArea requests;
	private QVBoxLayout requestsLayout;
	private final String IMG_PATH = "ImHereM03/img/";
	private Sistema sistema;
	private String userName;
	
	/**
	 * Construtor da classe.
	 * @param sistema
	 * @param username
	 */
	public AcceptFriendsDialog(Sistema sistema, String username){
		this.sistema = sistema;
		this.userName = username;
		this.setWindowTitle("Accept Friends");
		this.setWindowIcon(new QIcon(IMG_PATH + "icon.png"));
		this.setStyleSheet("QDialog{background-image: url("+IMG_PATH + "background.png);}");
		this.setFixedSize(300,300);
		this.insertLayout();
	}

	/**
	 * Metodo que insere o layout da classe.
	 */
	private void insertLayout() {
		this.requests = new QScrollArea();
		this.requests.setVerticalScrollBar(new QScrollBar());
		this.requests.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded);
		this.requests.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded);
		this.requests.setWidgetResizable(true);
		QWidget widget = new QWidget(this.requests);
		this.requestsLayout = new QVBoxLayout();
		/*
		 * TEste
		 */
		
		Iterator<String> friends;
		try {
			friends = sistema.getListaAmigos(userName).listIterator();
			while (friends.hasNext()) {
				String friend = friends.next();
				QPushButton friendButton = new QPushButton();
				friendButton.setText(sistema.getAtributoUsuario(friend, "nome"));
				requestsLayout.addWidget(friendButton);
			}
		} catch (ContaException e) {
			QMessageBox.critical(this, "Erro", e.getMessage());
		}
		this.requests.setFixedSize(210, 350);
		widget.setLayout(this.requestsLayout);
		this.requests.setWidget(widget);
		
	}
	
}
